<template>
	<view>
		<view class="tab-list">
			<u-tabs active-color="#de1f1c" :is-scroll="true" :bar-style="{borderRadius:'10rpx'}" :gutter="18" :height="80" :list="tab" :current="current" @change="change"></u-tabs>
		</view>
		<!-- 更多列表 热门新房 -->
		<view class="more-list">
			<view class="more-item u-flex" v-for="item in list" :key="item.id" @click="jumpMore(item.id)">
				<view class="image">
					<u-image width="206" height="160" border-radius="18" :src="imgUrl(item.images)"></u-image>
				</view>
				<view class="info u-flex-1">
					<view class="title u-flex">
						<view class="name u-flex-1 u-ellipsis">{{item.name}}</view>
						<view class="label">
							<text v-if="item.is_selected_switch">精选</text>
							<text v-if="item.status === '1'" class="wait">待{{current === 2 ? '租' : '售'}}</text>
							<text v-if="item.status === '2'">在{{current === 2 ? '租' : '售'}}</text>
						</view>
					</view>
					<view class="position u-ellipsis" style="height: 32rpx;">{{item.title}}</view>
					<view class="label-list u-ellipsis">
						<text v-for="f in item.housebaseset_features" :key="f.id">{{f.name}}</text>
					</view>
					<view class="price-box u-flex">
						<template v-if="current == 0">
							<!-- 新房 -->
							<view class="price">均价{{Number(item.unitprice)}}元/m²</view>
							<view class="text">建面{{Number(item.min_area)}}-{{Number(item.max_area)}}m²</view>
						</template>
						<template v-if="[1,4,5,6].includes(current)">
							<!-- 二手房 地皮 厂房 独栋 -->
							<view class="price">{{Number(item.totalprice)}}万</view>
							<view class="text">{{Number(item.unitprice)}}元/m²</view>
						</template>
						<template v-if="current == 2">
							<!-- 租房 -->
							<view class="price">{{Number(item.unitprice)}}元/月</view>
							<view class="text">{{item.housebaseset_housetype[0].name}}</view>
						</template>
						<template v-if="current == 3">
							<!-- 商铺 -->
							<view class="price">总价{{Number(item.totalprice)}}万</view>
							<view class="text">{{Number(item.unitprice)}}元/m²</view>
						</template>
						<!-- 已失效 -->
						<view class="dated-img" v-if="false">
							<image src="/static/icon/dated.png"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-empty v-if="isEmpty" text="暂无相关信息" margin-top="200"></u-empty>
		
		<view class="safe-area-inset-bottom"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tab: this.$app.TYPE_MAP,
				current: 0,
				isEmpty:!1,
				list:[],
				p:1,
				status:'loading'
			}
		},
		methods: {
			change(index) {
				this.current = index
				this.list = []
				this.p = 1
				this.getList()
			},
			getList(){
				this.isEmpty = !1
				this.$u.post('/api/user/getBrowseHouseLog',{
					build_type:this.current + 1,
					p:this.p
				}).then(res=>{
					res = res.map(item=>item.house_info)
					this.isEmpty = (this.p === 1 && res.length === 0) ? !0 : !1
					this.status = res.length  === 0 ? 'nomore' : 'loadmore'
					this.list = this.p == 1 ? res : this.list.concat(res)
				})
			},
			jumpMore(id){
				this.jump(`/pages/house/${this.$app.TYPE_MAP[this.current].key}/detail?id=${id}`)
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			if(this.status == 'loadmore'){
				this.p ++
				this.getList()
			}
		}
	}
</script>

<style lang="scss">
	.tab-list{border-bottom: 1rpx solid #eee;position: sticky;top: 0;left: 0;width: 100%;background-color: #fff;z-index: 9;}
	// 底部更多列表
	.more-list{
		background-color: #fff;padding: 0 30rpx 20rpx;position: relative;
		.more-item{
			padding: 30rpx 0 10rpx 0;position: relative;
			.dated-img{
				position: absolute;width: 120%;height: 100%;left: -10%;top: 0;background-color: rgba($color: #000000, $alpha: .1);
				image{display: block;width: 162rpx;height: 122rpx;position: absolute;right: 152rpx;top: 50%;transform: translateY(-50%);}
			}
			.image{
				image{width: 206rpx;height: 160rpx;border-radius: 20rpx;display: block;}
			}
			.info{
				margin-left: 20rpx;overflow: hidden;
				.title{
					.name{font-size: 30rpx;
							font-weight: bold;
							// line-height: 30rpx;
					  //   max-height: 60rpx;
					  //   overflow: hidden;
					  //   display: -webkit-box;
					  //   -webkit-line-clamp: 2;
					  //   -webkit-box-orient: vertical
					}
					.label{align-self: flex-start;
						text{background-color: $tc;color: #fff;font-size: 24rpx;padding: 2rpx 8rpx;border-radius: 6rpx;margin: 0 6rpx;}
						.wait{background-color: #999;}
					}
				}
				.position{font-size: 24rpx;color: #666;}
				.label-list{white-space: nowrap;
					text{color: #ffa100;font-size: 26rpx;margin-right: 20rpx;
						&:last-child{margin-right: 0;}
					}
				}
				.price-box{
					.price{color: #f00;font-size: 30rpx;font-weight: bold;}
					.text{margin-left: 30rpx;font-size: 26rpx;color: #666;}
				}
			}
			
		}
		.more{text-align: center;font-size: 30rpx;color: #666;padding: 20rpx 0 10rpx 0;
			.iconfont{margin-left: 14rpx;}
		}
	}
</style>
